package org.edu.jgame.cardgames;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

import org.newdawn.slick.*;

public final class CardStore {	
	
	final int [] values = {0,21,22,23,24,31,32,33,34,41,42,43,
			44,51,52,53,54,61,62,63,64,71,72,73,74,81,82,83,
			84,91,92,93,94,101,102,103,104,111,112,113,114,
			121,122,123,124,131,132,133,134,141,142,143,144};
	
	final Image[] images = new Image[values.length];
	
	public CardStore() throws SlickException {
		String s = "";
		try {
			FileInputStream fis = new FileInputStream("data/config");
			Scanner scanner = new Scanner(fis);
			scanner.nextLine();
			
			if(scanner.hasNext()) {
				s = scanner.nextLine();
			}
			s = s.split(" ")[1];
			scanner.close();
			fis.close();
		}
		catch(FileNotFoundException e) {
			
		}
		catch(IOException e) {
			
		}
		
		images[0] = new Image(s);	
		
		for(int i = 1; i < values.length; i++) {
			String link = "data/";
			link += Integer.toString(values[i]/10) + "-" + Integer.toString(values[i]%10) + ".png";
			
			images[i] = new Image(link);
		}
	}
	
	public Image getCard(int num) {
		for(int i = 0; i < values.length; i++) {
			if(values[i] == num) {
				return images[i];
			}
		}
		
		return null;
	}
}
